package com.sky.mapper;

import com.sky.entity.Orders;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;

@Mapper
public interface OrderMapper {

    @Options(useGeneratedKeys = true,keyProperty = "id")
    @Insert("INSERT INTO orders (number, STATUS, user_id, address_book_id, order_time, checkout_time, pay_method, pay_status,\n" +
            "amount, remark, phone, address, user_name, consignee, cancel_reason, rejection_reason, cancel_time,\n" +
            "estimated_delivery_time, delivery_status, delivery_time, pack_amount, tableware_number, tableware_status) VALUES\n" +
            "(#{number},#{status},#{userId},#{addressBookId},#{orderTime},#{checkoutTime},#{payMethod},#{payStatus},\n" +
            "#{amount},#{remark},#{phone},#{address},#{userName},#{consignee},#{cancelReason},#{rejectionReason},#{cancelTime},\n" +
            "#{estimatedDeliveryTime},#{deliveryStatus},#{deliveryTime},#{packAmount},#{tablewareNumber},#{tablewareStatus})")
    void insert(Orders orders);

    /**
     * 根据订单号和用户id查询订单
     * @param orderNumber
     * @param userId
     */
    @Select("select * from orders where number = #{orderNumber} and user_id= #{userId}")
    Orders getByNumberAndUserId(String orderNumber, Long userId);

    /**
     * 修改订单信息
     * @param orders
     */
    void update(Orders orders);
}
